// Ninf-G-XX, ver. 0.1
// Copyright 2011 National Institute of Advanced Industrial Science and Technology
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#define USE_CURL
#include "remote_matrix.hh"

// Endianness management
inline char system_endianness() {
  union { 
    int int_val;
    char c_val[sizeof(int)];
  } bg_endian = {0x01020304};
  
  if (bg_endian.c_val[0]==1)
    return BIGENDIAN;
  return LTLENDIAN;
}

matrix_t* _newMatrixArg(const unsigned int& nb_col,
                     const unsigned int& nb_row,
		     char * ptr)
{
  matrix_t* result = new matrix_t;
  result->desc.nb_col = nb_col;
  result->desc.nb_row = nb_row;
  result->desc.elt_size = sizeof(double);
  result->desc.order = ROWMAJOR;
  result->desc.endianness = system_endianness();
  result->data = ptr;
  
  return result;
}

double M[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};

int main(){
  matrix_t * mat = 
    _newMatrixArg(3, 3, (char *)M);
  
  //save_matrix("tempmat", *mat);
  put_matrix("http://localhost/upload.php", "c.out", *mat);
  return 0;

}
